<?php


namespace App\Utils\Logic\lak;

use App\Utils\Lib\MyEs;
class EsMultiple
{
    public static function EsMultipleSearch($query,$field,$from,$size){
        $es = new MyEs();
        //做高亮检索,多条件搜索
        $params = [
            'index' => $es->index,
            'body' => [
                'query' => [
                    'bool' => [
                        'must' => $query
                    ]
                ],
                //高亮
                'highlight'=>[
                    'pre_tags'=>[
                        "<span style='color: red'>",
                    ],
                    'post_tags'=>["</span>"],
                    'fields'=>[
                        $field =>new \stdClass()
                    ]
                ],
            ],
            'from'=>$from,//偏移量
            'size'=>$size,//每页显示条数
        ];
        $results = $es->client->search($params);
        $data = $results['hits']['hits'];
        return $data;
    }

}
